<!--案件评价-->
<template>
  <div>
    <tablePage ref="tablePage" :searchForm.sync="searchForm" :searchFormRules="searchFormRules" :requestFunc="requestFunc">
      <template slot="search-form">
        <el-form-item label="提交时间" prop="dateRange">
          <el-date-picker type="daterange" v-model="searchForm.dateRange" range-separator="至" value-format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
        </el-form-item>

        <el-form-item label="案件名称" prop="title">
          <el-input v-model="searchForm.title" placeholder="请输入案件名称关键字"></el-input>
        </el-form-item>

        <el-form-item label="评价状态" prop="appraiseStatus">
          <el-select v-model="searchForm.appraiseStatus" placeholder="请选择">
            <el-option v-for="item in appraiseStatusArr" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
      </template>

      <template slot="rows">
        <tableColumnsCommon fixed="right" type="appraise" @showDetailsDialog="handleShowDialog('detailsDialog', $event)" @showLeaveMessageDialog="handleShowDialog('leaveMessageDialog', $event)"></tableColumnsCommon>
      </template>
    </tablePage>

    <detailsDialog ref="detailsDialog" type="appraise" :extendHeight="currentRow.appraiseStatus === 'N' ? '170px' : '0px'" :visible.sync="detailsDialog.visible" :id="currentRow.id" :canShowAppraiseForm="true" @read="handleReadComment">
      <template v-slot:extend="{ details }">
        <div v-if="details.appraiseStatus === 'N'" style="border-top: 1px solid #cccccc; padding-top: 10px">
          <!-- 评价模块-->
          <el-form ref="appraiseForm" :model="appraiseForm" :rules="appraiseFormRules" label-width="120px">
            <el-row :gutter="0">
              <el-col :span="9">
                <el-form-item label="整体满意度：" prop="satisfiedScore">
                  <startAppraise v-model="appraiseForm.satisfiedScore"></startAppraise>
                </el-form-item>
              </el-col>
              <!--              <el-col :span="9">-->
              <!--                <el-form-item label="处理时效性：" prop="processEffectiveScore">-->
              <!--                  <startAppraise v-model="appraiseForm.processEffectiveScore"></startAppraise>-->
              <!--                </el-form-item>-->
              <!--              </el-col>-->
              <!--              <el-col :span="6">-->
              <!--                <el-form-item label="处理有效性：" prop="processAvailableScore">-->
              <!--                  <startAppraise v-model="appraiseForm.processAvailableScore"></startAppraise>-->
              <!--                </el-form-item>-->
              <!--              </el-col>-->
            </el-row>
            <el-form-item label="评价内容：" prop="comment">
              <el-input v-model="appraiseForm.comment" show-word-limit maxlength="1000" placeholder="请输入评价内容" type="textarea" :autosize="{ minRows: 6 }"></el-input>
            </el-form-item>
          </el-form>
        </div>
      </template>
      <template v-slot:footer-btn="{ details }">
        <el-button v-if="details.appraiseStatus === 'N'" @click="handleSubmitAppraise" :loading="submitting" type="primary">提交评价</el-button>
      </template>
    </detailsDialog>
  </div>
</template>

<script>
import tablePage from "@/components/tablePage/index.vue";
import searchFormItemsCommon from "@/views/workOrder/components/searchFormItemsCommon/searchFormItemsCommon";
import tableColumnsCommon from "@/views/workOrder/components/tableColumnsCommon";
import detailsDialog from "./components/detailsDialog";
import startAppraise from "@/components/startAppraise/index.vue";

import * as workOrderApi from "@/api/workOrder/index";
import { workOrderStatus, timeRemaining, workOrderPublicStatus } from "@/utils/filters";
import * as mixins from "@/utils/mixins";
import * as validators from "@/utils/validators";
import { dict2Array } from "@/utils/common";
import { workOrderAppraiseStatusDict } from "@/utils/dict";
import { initSearchFormRules } from "@/views/workOrder/components/searchFormItemsCommon/mixin";

export default {
  name: "accepted",
  mixins: [mixins.affirm, mixins.form],
  components: { tablePage, searchFormItemsCommon, detailsDialog, tableColumnsCommon, startAppraise },
  filters: { workOrderStatus, timeRemaining, workOrderPublicStatus },
  data() {
    return {
      searchForm: {
        title: "",
        dateRange: [],
        appraiseStatus: "",
      },
      searchFormRules: initSearchFormRules(),
      appraiseStatusArr: dict2Array(workOrderAppraiseStatusDict, 1),
      currentRow: {},
      detailsDialog: {
        editDetails: {},
        visible: false,
      },
      appraiseForm: {
        comment: "",
        processAvailableScore: 0,
        processEffectiveScore: 0,
        satisfiedScore: 0,
      },
      submitting: false,
      appraiseFormRules: {
        processAvailableScore: [{ required: true, message: "请填写整体满意度" }, { validator: validators.min(1, "请填写整体满意度") }],
        processEffectiveScore: [{ required: true, message: "请填写处理时效性" }, { validator: validators.min(1, "请填写处理时效性") }],
        satisfiedScore: [{ required: true, message: "请填写处理有效性" }, { validator: validators.min(1, "请填写处理有效性") }],
      },
    };
  },
  created() {},
  methods: {
    requestFunc: workOrderApi.appraise.list,
    rePlayLoadData() {
      this.$refs.tablePage.playLoadData();
      if (this.detailsDialog.visible) {
        this.$refs.detailsDialog.playLoadData();
      }
    },
    handleReadComment() {
      // this.currentRow.appraiseFlag = 'N'
    },
    handleReadLeaveMessage() {
      this.currentRow.wordsFlag = "N";
    },
    handleShowDialog(type, row) {
      this[type].visible = true;
      this.currentRow = row;
    },
    handleSubmitAppraise() {
      this.validateAndConfirm("appraiseForm", "确认评价吗？")
        .then(() => {
          this.submitting = true;
          return workOrderApi.appraise
            .appraise({
              ...this.appraiseForm,
              workOrderNo: this.currentRow.workOrderNo,
            })
            .then((res) => {
              this.$message.success("提交成功");
              this.rePlayLoadData();
            });
        })
        .finally(() => (this.submitting = false));
    },
  },
};
</script>

<style scoped></style>
